#include <chrono>
#include <iostream>
#include <utility>

using namespace std::chrono;

class Timer {
public:
  void start() { start_ = system_clock::now(); }

  void end() { end_ = system_clock::now(); }

  void out(const char *msg = "") {
    duration<double> d = end_ - start_;
    std::cout << msg << " Time Cost: " << d.count() << "\n";
  }

private:
  time_point<system_clock> start_;
  time_point<system_clock> end_;
};

constexpr long fib(long n) { return (n < 2) ? 1 : fib(n - 1) + fib(n - 2); }

int main(int argc, char *argv[]) {

  Timer timer;

  long n = 40;

  timer.start();
  long r1 = fib(n);
  timer.end();
  timer.out("without constexpr");

  timer.start();
  constexpr long r2 = fib(40); // use constexpr function prefer metaprogramming
  timer.end();
  timer.out("with constexpr");

  return 0;
}
